package Offer.offer;

import java.util.Stack;

/**
 * 两个栈实现队列
 * @author leiwenkang
 * @date 2020/4/6
 */
public class Test07a两个栈实现队列 {
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();

    public void add(int value) {
        stack1.push(value);
    }

    public int remove() {
        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }
        }
        if (stack2.isEmpty()) {
            throw new RuntimeException("列表为空");
        }
        return stack2.pop();
    }



}
